/*
 * @Author: your name
 * @Date: 2020-07-29 13:07:46
 * @LastEditTime: 2020-08-07 18:58:05
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \H52002-VueMobile-accp\honeybud\src\utils\http.js
 */ 
import axios from 'axios';
import { Toast } from 'vant';

const get =({url,parmas})=>{
    return axios({
        url,
        method:'get',
        parmas
    })
    .then((result)=>{
        return result.data
    })
    .catch((err)=>{
        return err.message
    })
}

// Set config defaults when creating the instance
const instance = axios.create({
    baseURL: 'http://localhost:3000'
  });
// 添加请求拦截器
instance.interceptors.request.use(function (config) {
    // 在发送请求之前做些什么
    return config;
  }, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
  });

// 添加响应拦截器
instance.interceptors.response.use(function (response) {
    // 对响应数据做点什么
console.log('响应拦截');
let {code,msg} = response.data;
      let type = code==0?'fail':'success'
      Toast({
        message:msg,
        type
      })
    return response;
  }, function (error) {
    // 对响应错误做点什么
    return Promise.reject(error);
  });

export default instance
export {
    get,
}